<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$orderby='paixu asc';
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('core_account_store_group',$params,array($pindex,$psize),$total,array('id','title'),'id',$orderby);
	if($list){
		foreach($list as &$row){
			$row['createtime']=date('y-m-d',$row['createtime']);
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'门店分类'),
		),
		'list'=>array('data'=>'list','list'=>array(
			'0'=>array('type'=>'string','title'=>'分类标题','name'=>'title'),
		)),
		'search_one'=>array('name'=>'title'),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('core_account_store_group',array('id'=>$id));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'分类',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'门店分类列表'),
			'1'=>array('op'=>'edit','title'=>'门店分类编辑'),
		),
		'edit'=>array(
			'0'=>array('type'=>'string','title'=>'标题','name'=>'title', 'help'=>'' ),
			'1'=>array('type'=>'string','title'=>'门店排序','name'=>'paixu', 'help'=>'填写100以内正整数，数值越小越靠前' ),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$data=array(
		'title'=>trim($post['title']),
		'paixu'=>intval($post['paixu']),
	);
	$id=intval($post['id']);
	if($id){
		pdo_update('core_account_store_group',$data,array('id'=>$id));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('core_account_store_group',$data);
	}
	exi('保存成功！');
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('core_account_store_group',array('id'=>$id));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			if(intval($id)){
				pdo_delete('core_account_store_group',array('id'=>intval($id)));
			}
		}
	}
	exi('删除成功！');
}